package top.truism.stack;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * 使用两个栈实现队列
 */
public class ListImplByStack<T> {

    private Deque<T> dataStack;

    private Deque<T> tempStack;

    public ListImplByStack() {
        dataStack = new ArrayDeque<>();
        tempStack = new ArrayDeque<>();
    }

    public void enQueue(T t) {
        while (!dataStack.isEmpty()) {
            tempStack.push(dataStack.pop());
        }
        dataStack.push(t);
        while (!tempStack.isEmpty()) {
            dataStack.push(tempStack.pop());
        }
    }

    public T deQueue() {
        return dataStack.pop();
    }
}
